<template>
<div class="login-container">
  <el-form 
  ref="searchForm"
  :model="temp"
  :rules="rules"
  class="login-form">
    <div class="title-container">
      <h3 class="title">证书查询</h3>
    </div>
    <div class="tit">证书编号:</div>
    <el-input
      v-model="temp.code"
      placeholder="请输入证书编号"
      class="code"
    />
    <!-- <el-form-item label="证书编号" prop="code">
      <el-input placeholder="请填写证书编号" v-model="temp.code" />
    </el-form-item> -->
    <el-button
      v-waves
      type="primary"
      icon="el-icon-search"
      @click="search"
    >查询</el-button>
    <div class="description" v-if="visiable">{{description}}</div>
  </el-form>
</div>
</template>

<script>
import waves from '@/directive/waves' // waves directive
  export default {
    name: 'Search',
    components: { },
    directives: { waves },
    data() {
      return {
        temp: {
          code: '',
        },
        visiable: true,
        description: '',
        certificates: [{
          code: '123456',
          description: '张三'
        }],
        rules: {
          code: [{ required: true, message: '证书编号必须填写', trigger: 'blur' }],
        }
      }
    },
    created() {
      this.description = ''
      this.$nextTick(() => {
        this.$refs['searchForm'].clearValidate()
      })
    },
    mounted() {
    },
    destroyed() {
      // window.removeEventListener('storage', this.afterQRScan)
    },
    methods: {
      search() {
        this.clear()
        this.$refs['searchForm'].validate((valid) => {
          if (valid) {
            const certificate = this.certificates.find(a=>a.code === this.temp.code)
            if (certificate) {
              this.description = certificate.description
            } else{
              this.description = '证书不存在'
            }
          }
        })        
      },
      clear() {
        this.description = ''
      }
    }
  }
</script>

<style lang="scss" scoped>
  $bg:#2d3a4b;
  $dark_gray:#dee6eb;
  $light_gray:rgb(215, 223, 216);

  .login-container {
    min-height: 100%;
    width: 100%;
    background-image: linear-gradient(62deg, #dee6eb 10%, #ede8f1 100%);
    overflow: hidden;
    .login-form

  {
    position: relative;
    width: 520px;
    max-width: 100%;
    padding: 160px 35px 0;
    margin: 0 auto;
    overflow: hidden;

    .tit {
      display: inline-block;
      margin: 0 10px 0 0;
    }
    .code {
      width: 150px;
      margin: 0 10px 0 0;
    }
    .description {
      margin: 10px 0 0 0;
    }
  }

  .tips {
    font-size: 14px;
    margin-bottom: 10px;
    text-align: center;
    span

  {
    &:first-of-type

  {
    margin-right: 16px;
  }

  }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;
    .title

  {
    font-size: 26px;
    margin: 0px auto 40px auto;
    text-align: center;
    font-weight: bold;
  }

  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    cursor: pointer;
    user-select: none;
  }

  .thirdparty-button {
    position: absolute;
    right: 0;
    bottom: 6px;
  }

  @media only screen and (max-width: 470px) {
    .thirdparty-button {
      display: none;
    }
  }
  }
</style>
